
/**
 * copyright(c) 2013 www.jiongshibaoliao.com, All Rights Reserved.
 * project: jiongshibaoliao 
 * author: 曾帅
 * date: 2014-1-16 上午11:03:48
 * version: v1.0
 */

package com.jiongshibaoliao.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiongshibaoliao.common.mybatis.Page;
import com.jiongshibaoliao.common.mybatis.PageBean;
import com.jiongshibaoliao.dao.BaseDao;
import com.jiongshibaoliao.dao.CommentDao;
import com.jiongshibaoliao.model.Comment;
import com.jiongshibaoliao.service.CommentService;
import com.jiongshibaoliao.util.DateUtils;

/**
 * @project jiongshibaoliao
 * @author 曾帅 
 * @version 1.0
 * @date 2014-1-16 上午11:03:48   
 */

@Service
public class CommentServiceImpl extends BaseServiceImpl implements CommentService {

	@Autowired
	public CommentDao commentDao;
	
	/**
	 * 
	 * @author 曾帅
	 * @version 1.0
	 * @date 2014-1-16 上午11:04:13
	 * @see com.jiongshibaoliao.service.CommentService#getCommentPageList(com.jiongshibaoliao.common.mybatis.PageBean, com.jiongshibaoliao.model.Comment)
	 */
	@Override
	public Page getCommentPageList(PageBean pageBean, Comment comment) {
		Page page = commentDao.getCommentPageList(pageBean, comment);
		List<Map<String, Object>> commentMapList = new ArrayList<Map<String, Object>>();
		for(Object result : page.getlistResult()) {
			Map<String, Object> commentMap = new HashMap<String, Object>();
			commentMap.put("comment", result);
			commentMap.put("commentTime", DateUtils.getInterval(((Comment) result).getCreateDate()));
			commentMap.put("user", commentDao.getEntityById(((Comment) result).getUserId()));
			
			commentMapList.add(commentMap);
		}
		page.setlistResult(commentMapList);
		
		return page;
	}
	
	/**
	 * 
	 * @author 曾帅
	 * @version 1.0
	 * @date 2014-1-16 上午11:04:13
	 * @see com.jiongshibaoliao.service.impl.BaseServiceImpl#getDao()
	 */
	@Override
	public BaseDao getDao() {
		return commentDao;
	}

}
